<?php
/**
 * Created by PhpStorm.
 * User: Windows
 * Date: 2015/11/17
 * Time: 11:11
 */
class JsonModel extends BaseModel
{
    private $_table;
    protected $_isbug = false;
    public function __construct() {
        parent::__construct();
    }
    /**
     * @param $data
     * @return string
     */
    public function addPublish($data){
        $this->_table = new self ();
        $db = $this->_table->getAdapter ();

        $db->insert("demand", $data );
        return $productId = $this->_db->lastInsertId("demand");
    }

    /**
     * @param $id
     * @return array
     */
    public function getBusinessById($id){
        $this->_table = new self ();
        $db = $this->_table->getAdapter ();
        $select = $db->select ();
        $sql = $select->from ("users_invoice",array("id as business_id","business_name","contacts","mobile","business_phone","is_default"))
            ->where ("id = '{$id}'")
            ->__toString ();
        if ($this->_isbug == true) {
            echo  __METHOD__.": ".$sql . "<hr/>";
        }
        $data =  $db->fetchRow( $sql );
        return $data;
    }

    public function getAreaList($id){
        $this->_table = new self ();
        $db = $this->_table->getAdapter ();
        $select = $db->select ();
        $sql =$select->from("region","*")->where("region_pid = '{$id}'") ->__toString ();
        if ($this->_isbug == true) {
            echo  __METHOD__.": ".$sql . "<hr/>";
        }
        $data =  $db->fetchAll( $sql );
        return $data;
    }




}